package com.inspur.dgov.common.boot.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.inspur.dgov.common.tool.constant.AppConstant;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * mybatisplus 配置
 *
 * @Author chiyupei
 * @Date 19/7/1 下午4:15
 * @Version 1.0
 * @Description mybatisplus 配置
 */
@Configuration
@MapperScan("com.inspur.dgov.**.mapper.**")
public class MybatisPlusConfiguration {

    /**
     * 分页插件
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(PaginationInterceptor.class)
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /**
     * SQL执行效率插件
     *
     * @return PerformanceInterceptor
     */
    @Bean
    @Profile({AppConstant.DEV_CODE, AppConstant.TEST_CODE})
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }
}
